import java.lang.reflect.Array;
import java.util.Arrays;

public class MyArrayList<T> {
    private Object[] elem = new Object[10];
    private int UsedSize;
    public void DisPlay(){
        for (int i = 0; i < UsedSize; i++) {
            System.out.print(elem[i] + " ");
        }
    }
    //判空
    public Boolean isFull(){
        if(this.elem.length == UsedSize){
            return true;
        }else {
            return false;
        }
    }
    //添加
    public void Add(int pos,T ret){
        if(pos < 0 || pos > UsedSize){
            System.out.println("出错");
        }
        if(isFull()){
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        for (int i = UsedSize - 1; i >= pos ; i--) {
            this.elem[i+1] = this.elem[i];
        }
        this.elem[pos] = ret;
        UsedSize++;
    }
    //检查
    private void ChickArray(int pos){
        if(pos < 0 || pos >= UsedSize){
            System.out.println("出错");
        }
        return;
    }
    //查找
    public int Find(T date){
        for (int i = 0; i < UsedSize; i++) {
            if(this.elem[i].equals(date)){
                return i;
            }
        }
        return -1;
    }
    //修改下标位置的数据
    public void Modify(int pos,T date){
        ChickArray(pos);

            this.elem[pos] = date;

    }
    //删除第一次出现的数据
    public void remove(T date){
        int index = Find(date);
        if (index == -1){
            System.out.println("没找到");
            return;
        }
        for (int i = index; i < this.UsedSize -1; i++) {
                this.elem[i] = this.elem[i+1];
        }
        this.UsedSize--;
    }
    //获取长度
    public int getUsedSize(){
        return this.UsedSize;
    }
    public void clear(){
        this.UsedSize = 0;
    }
}
